<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#detailPan {
	width: 100%;
	height: 100%;
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.level1Class {
	margin-left: 10px;
}

.level2Class {
	margin-left: 30px;
}

.level3Class {
	margin-left: 50px;
}

.deepDark {
	background-color: #CCC488;
}

.normalDark {
	background-color: #FFF7BB;
}

.lowDark {
	
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}
</style>
<script type="text/javascript">

	var radioValue = [ {
		id : 1,
		text : "长期工"
	}, {
		id : 0,
		text : "短期工"
	} ];
</script>

</head>
<body>
	<ul id="popupMenu" class="mini-menu" style="display: none;">
		<li iconCls="icon-addnew" onclick="add(1)" >长期工</li>
		<li iconCls="icon-addnew" onclick="add(0)" >短期工</li></ul>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="300px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a> 企业：<span
					class="nameTitle">未选择</span></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;
						<div id="typeBtn" class="mini-radiobuttonlist" repeatItems="1"
							repeatLayout="table" repeatDirection="vertical"
							style="float: left; margin-top: 4px;" textField="text"
							valueField="id" value="1" onvaluechanged="chageState"
							data="radioValue"></div> 生效日期:&nbsp;&nbsp;<input id="starting"
						class="mini-datepicker" style="width: 100px;" showNullItem="false"
						valueField="" onvalidation="" allowInput="false"
						emptyText="起始期间..." nullItemText="&lt;无&gt;" /> <span
						style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect_2" tooltip="查询" plain="true">查询</a>
				</span><a width="100px"></a> &nbsp;&nbsp;<span id="separatorId2"
					class="separator"> <a class="mini-menubutton" id="addBtn" menu="#popupMenu"
						iconCls="icon-add" plain="true" onclick="">新增</a></span></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px;">
				<div class="mini-fit">
					<div class="mini-splitter" style="width: 100%; height: 100%;">
						<div size="320px" showCollapseButton="true">
							<div id="treegrid1" class="mini-treegrid"
								style="height: 100%; width: 100%;" showTreeIcon="true"
								borderStyle="border:1;" onbeforeload="treeBeforeLoad"
								pagesize="50" sizeList="[50,100,200,500]" showPager="false"
								treeColumn="OrgName" idField="OrgNo"
								ondrawcell="ondatagridDrawCell" onrowclick="orgSelect"
								parentField="ParentNo" resultAsTree="false" expandOnLoad="true"
								showPageInfo="false" showFilterRow="true">
								<div property="columns">
									<div type="checkcolumn" field="Action" width="70px"
										headerAlign="center" align="center">
										<a class="mini-button" property="filter" id="removeBtn"
											iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch()">清除
										</a>
									</div>
									<div name="OrgName" field="OrgName" width="100%"
										headerAlign="center" align="left" allowSort="true">
										企业名称<input id="orgFilter" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect_1" emptyText="筛选..."
											onenter="onselect_1" />
									</div>
								</div>
							</div>
						</div>
						<div showCollapseButton="true">
							<div id="datagrid2" class="mini-datagrid gridFull"
								borderStyle="border:1;" showReloadButton="true" pagesize="100"
								sizeList="[20,50,100,200]" allowCellWrap="true"
								allowHeaderWrap="true" idField="No" multiSelect="true"
								showPager="true" allowAlternating="true"
								ondrawcell="ondatagrid1DrawCell_2"
								onrowdblclick="dbClick"
								style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
								collapseGroupOnLoad="false" showColumnsMenu="true"
								showFilterRow="true" onshowrowdetail="onShowRowDetail">
								<div property="columns">
									<div type="indexcolumn" width="40px"></div>
									<div field="Action" width="70px" headerAlign="center"
										align="center">
										<a class="mini-button" property="filter" id="removeBtn"
											iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch_2">清除
										</a>
									</div>
									<div field="StartTime" width="120px" headerAlign="center"
										align="center" allowSort="true" dateFormat="yyyy-MM-dd">开始日期</div>
									<div field="EndTime" width="120px" headerAlign="center"
										align="center" allowSort="true" dateFormat="yyyy-MM-dd">结束日期</div>
									<div field="WorkDay" width="80px" headerAlign="center"
										align="center" allowSort="true">要求工作天数</div>
									<div field="TypeText" width="100px" headerAlign="center"
										align="center" allowSort="true">
										返费类型<input id="filter1" property="filter"
											class="mini-combobox" style="width: 100%;"
											url="<c:url value='/common/type/reward_type' />" textField="RewardType"
											valueField="TypeNo" onValueChanged="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="SourceType" width="100px" headerAlign="center"
										align="center" allowSort="true">
										返费对象<input id="filter2" property="filter"
											class="mini-combobox" style="width: 100%;"
											url="<c:url value='/source/type' />" textField="SourceType"
											valueField="Id" onValueChanged="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="TotalAmount" width="100px" headerAlign="center"
										align="right" dataType="currency" allowSort="true">返费总额(元)</div>
									<div field="UserName" width="100px" headerAlign="center"
										align="center" allowSort="true">创建人</div>
									<div field="CreateTime" width="140px" headerAlign="center"
										align="center" allowSort="true"
										dateFormat="yyyy-MM-dd HH:mm:ss">创建时间</div>
									<div name="emptyCol" width='100%' headerAlign="center"
										align="center" cellStyle="padding:0;"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id="detailPan" class="subPageFrame" frameborder="0"> </iframe>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		mini.parse();

		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';
		var type = 1;
		var state = 1;
		var nature = 1;//性质

		var filterHelper = gridFilter();
		var filterHelper2 = gridFilter();
		
		var typeBtn = mini.get("typeBtn");
		var datagrid1 = mini.get("treegrid1");
		var datagrid2 = mini.get("datagrid2");
		var splitpan = mini.get("splitterPan");
		var orgFilter = mini.get("orgFilter");
		var filter0 = mini.get("filter0");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var mapList = new Array();
		var orgNo = null;
		var orgName = null;

		var starting = mini.get("starting");
		var ending = mini.get("ending");

		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		function checkMap() {
			status2();
			$("#check").hide();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/public/map" />');
		}
		function onselect_1() {
			var filterValue0 = orgFilter.getValue();
			filterHelper.clearFilterData();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("OrgName",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function onselect_2() {
			filterHelper2.clearFilterData();
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			if(!state){
				state = typeBtn.getValue();
			}
			if (state != "") {
				var filterdata = filterHelper.formFilterData("Nature",
						state, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("RewardType",
						filterValue1, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("SourceTypeId",
						filterValue2, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			var filterValue3 = starting.getValue();
			var filterValue4 = ending.getValue();
			if (filterValue3 && filterValue4 && filterValue3 > filterValue4) {
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("StartTime",
						filterValue3, '', 'GREATER_EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue4 != "") {
				var filterdata = filterHelper.formFilterData("StartTime",
						filterValue4, '', 'LESS_EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			loadGrid2(orgNo);

		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/org/list' />";
			datagrid1.setUrl(url);
			datagrid1.load(postData, function() {
				var row = datagrid1.getRow(0);
				if (row) {
					datagrid1.setSelected(row);
					orgNo = row.OrgNo;
					orgName = row.OrgName;
					$('.nameTitle').html(orgName);
					onselect_2();
				}
			});
		}
		function orgSelect() {
			var row = datagrid1.getSelected();
			if (!row) {
				return;
			}
			orgNo = row.OrgNo;
			if (!orgNo) {
				mini.alert('数据有误 ，请联系管理员处理！');
				return;
			}
			orgName = row.OrgName;
			$('.nameTitle').html(orgName);
			onselect_2();
		}
		function search(){
			
		}
		function loadGrid2(orgNo) {
			var filterData = filterHelper2.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/config/reward/list/' />" + orgNo;
			datagrid2.load(url);
			datagrid2.load(postData);
		}
		function chageState() {
			state = typeBtn.getValue();
			var row = datagrid1.getSelected();
			orgNo = row.OrgNo;
			if (!row || !row.OrgNo) {
				mini.alert('请选择企业！');
				return;
			}
			onselect_2();
		}
		function removeSearch() {
			orgFilter.setValue();
			orgFilter.setText();
			filterHelper.clearFilterData();
			loadGrid1();
		}
		function removeSearch_2() {
			filter1.setValue();
			filter2.setValue();
			starting.setValue();
			starting.setText();
			ending.setValue();
			ending.setText();
			filterHelper2.clearFilterData();
			//loadGrid2(orgNo);
			onselect_2();
		}
		function ondatagridDrawCell(e) {
			var field = e.field;
			var row = e.row;
			var grade = row.Grade;
			var cellCls = null;
			switch (grade) {
			case 1:
				cellCls = "deepDark";
				break;
			case 2:
				cellCls = "normalDark";
				break;
			default:
				cellCls = "lowDark";
				break;
			}
			e.cellCls = cellCls;
		}
		function ondatagrid1DrawCell_2(e) {
			var row = e.row;
			var field = e.field;
			var map = new Object();
			if (field == "Action") {
				var id = row.Id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:check('+id+')">[查看]</a>';
			}
		}

		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#resetBtn').show();
			$("#check").show();
			$("#exportBtn").show();
			$("#separatorId").show();
			$("#separatorId2").show();
			$("#addBtn").show();
			$("#deleteBtn").show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#resetBtn').hide();
			$("#check").hide();
			$("#exportBtn").hide();
			$('#separatorId').hide();
			$('#separatorId2').hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
		}
		function status3Show() {
			$('#rebackBtn').hide();
			$('#resetBtn').show();
			$("#check").hide();
			$('#separatorId').hide();
			$('#separatorId2').hide();
			$("#exportBtn").hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
		}
		function reloadList() {
			datagrid2.reload();
		}

		function treeBeforeLoad(e) {
			var filterData = filterHelper.getFilterData();
			e.data.filterdata = mini.encode(filterData);
		}
		function add(type) {
			nature = type;
			var row = datagrid1.getSelected();
			if (!row) {
				mini.alert('请选择企业！');
				return;
			}
			var orgNo = row.OrgNo;
			if (!orgNo) {
				mini.alert('企业数据有误，请联系管理员处理！');
				return;
			}
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/config/reward/add/" />'+orgNo);
		}
		function dbClick(e){
			var row = e.row;
			if(row){
				check(row.Id);
			}
		}
		function check(id) {
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/config/reward/check/" />'+id);
		}
	</script>
</body>
</html>